package com.msconfig.utils;

/*
 * author: caojunhao
 * date  : 2020/5/9
 * desc  :
 */

public class DoubleToLocationUtil {

    /**
          *
          * @note double位置 转换成  度 分 秒
          *
          * */

    public static String dblToLocation(double data){//113.429559375
        String ret_s = "";
        int tmp_i_du = (int)data;
        ret_s = String.valueOf(tmp_i_du)+"°";
        //度小数部分
        double tmp_d_du = data-tmp_i_du;
        int tmp_i_fen = (int)(tmp_d_du*60);
        ret_s = ret_s.concat(String.valueOf(tmp_i_fen)+"′");
        double tmp_d_fen = tmp_d_du*60 - tmp_i_fen;
        double tmp_i_miao = (tmp_d_fen*60);
        String miao;
        if(String.valueOf(tmp_i_miao).length()>=7){//保留4位小数
            miao=String.valueOf(tmp_i_miao).substring(0,7);
        }else{
            miao=String.valueOf(tmp_i_miao);
        }
        ret_s = ret_s.concat(miao+"″");
        return ret_s;

    }

    //经纬度度分秒转换为小数
    public static double convertToDecimal(String location){//128°44'122''
        double du = Double.parseDouble(location.substring(0,location.indexOf("°")));
        double fen=Double.parseDouble(location.substring(location.indexOf("°")+1,location.indexOf("′")));
        double miao=Double.parseDouble(location.substring(location.indexOf("′")+1,location.indexOf("″")));
        if(du<0)
            return -(Math.abs(du)+(Math.abs(fen)+(Math.abs(miao)/60))/60);
        return Math.abs(du)+(Math.abs(fen)+(Math.abs(miao)/60))/60;
    }



}
